package com.app.business.service;

import com.app.business.model.BzYyDate;
import com.app.business.model.CarLot;
import com.app.system.jpa.JpaBaseDao;
import com.app.system.jpa.PageBean;
import com.app.system.jpa.Wrapper;
import com.app.system.utils.CollectionUtils;
import com.app.system.utils.dataType.StringUtils;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Service;

import javax.persistence.Query;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 办证预约状态
 * Created by szy on 2024/12/30
 */
@SuppressWarnings(value = "ALL")
@Service
public class BzYyDateService extends JpaBaseDao<BzYyDate, Integer> {

    public PageBean<BzYyDate> bzYyDatePageBean() {
        //查询语句
        StringBuffer query = new StringBuffer(" b from BzYyDate b ");
        //默认排序(PageBean指定排序字段类型的话，则默认排序不使用)
        StringBuffer orderBy = new StringBuffer(" b.date");
        Wrapper wrapper = new Wrapper(query, orderBy);
        wrapper.initSearchParams();
        return this.pageHql(wrapper);
    }

    /**
     * 得到可预约的天数
     * @return
     */
    public List<Map> getBzYyDateStrList() {
        StringBuffer sql = new StringBuffer("SELECT DATE_FORMAT(b.date, '%Y-%m-%d') as 'date',b.time FROM bz_yy_date b  ");
        sql.append("WHERE DATE_FORMAT(b.date, '%Y-%m-%d') >= DATE_FORMAT(NOW(), '%Y-%m-%d') AND b.status = 1 ");
        sql.append("ORDER BY b.date,b.time ");
        Query query = this.entityManager.createNativeQuery(sql.toString());
        List<Map> mapList = query.unwrap(org.hibernate.SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
        return mapList;
    }


    /**
     * 得到可预约的天数
     * @return
     */
    public List<BzYyDate> getBzYyDateList() {
        StringBuffer sql = new StringBuffer("SELECT * FROM bz_yy_date b  ");
        sql.append("WHERE DATE_FORMAT(b.date, '%Y-%m-%d') > DATE_FORMAT(NOW(), '%Y-%m-%d') AND b.status = 1 ");
        sql.append("ORDER BY b.date LIMIT 5 ");
        List<BzYyDate> bzYyDateList = entityManager.createNativeQuery(sql.toString()).getResultList();
        return bzYyDateList;
    }
}
